package com.wxyzz.canteenadmin.shop.employee.controller;

import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.shop.employee.VO.EmployeeVO;
import com.wxyzz.canteenadmin.shop.employee.param.AddEmpParam;
import com.wxyzz.canteenadmin.shop.employee.param.EmployeePageParam;
import com.wxyzz.canteenadmin.shop.employee.service.EmployeeService;
import com.wxyzz.canteencommon.common.R;
import com.wxyzz.canteencommon.entity.shop.employee.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * --- 加油，努力 ---
 *
 * @Author XYP
 * @Date 2024/10/10
 * @Solgne 从想做到能做
 * @Desc
 */
@RestController
@RequestMapping("/shop/employee")
@CrossOrigin
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/page")
    public R page (EmployeePageParam employeePageParam) {
        PageInfo<EmployeeVO> employeePageInfo = employeeService.page(employeePageParam);
        return R.ok(employeePageInfo);
    }

    @GetMapping("/empInfo")
    public R empInfo (Integer id) {
        Employee employee = employeeService.findById(id);
        return R.ok(employee);
    }

    @GetMapping("/del")
    public R del (Integer id) {
        employeeService.deleteById(id);
        return R.ok();
    }

    @GetMapping("/delBatch")
    public R delBatch (@RequestParam("ids")List<Integer> ids) {
        employeeService.delBatch(ids);
        return R.ok();
    }

    @PostMapping("/add")
    public R add (@RequestBody AddEmpParam addEmpParam) {
        employeeService.add(addEmpParam);
        return R.ok();
    }

    @PostMapping("/update")
    public R add (@RequestBody Employee employee) {
        System.out.println(employee);
        employeeService.update(employee);
        return R.ok();
    }

    //上传文件
    @PostMapping("/upload/excel")
    public R uploadExcel(MultipartFile file){
        employeeService.importUnit (file);
        return R.ok();
    }
    //导出文件
    @GetMapping("/download/excel")
    public R downloadExcel (HttpServletResponse response){
        employeeService.exportExcel(response);
        return R.ok();
    }

}
